package com.aistar.service.impl;

import com.aistar.mapper.ProductMapper;
import com.aistar.pojo.Product;
import com.aistar.pojo.ProductExample;
import com.aistar.service.ProductService;
import com.aistar.util.ServerResponse;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;

    @Override
    public PageInfo<Product> getAllpage(int pageNum) {
        return null;
    }

    @Override
    public List<Product> getByBigId(int bigId) {
        return null;
    }

    @Override
    public ServerResponse save(Product product) {
        return null;
    }

    @Override
    public ServerResponse modifyStatus(Product product) {
        return null;
    }

    @Override
    public ServerResponse modify(Product product) {
        return null;
    }

    @Override
    public ServerResponse getById(Integer id) {
        Product product= productMapper.selectByPrimaryKey(id);
        if (product != null){
            return ServerResponse.getDataSuccess(product);
        }else {
            return ServerResponse.getDataFailed("查询失败");
        }

    }

    @Override
    public ServerResponse getAll() {
        return null;
    }


//    /*查询所有*/
//   @Override
//   public List<Product> getProducts() {
//        ProductExample example = new ProductExample();
//       List<Product> list = productMapper.selectByExample(example);
//       return list;
//    }

    /*根据商品类别查询*/
   /* @Override
    public List<Product> getByType(int bigId) {
        ProductExample example = new ProductExample();
        ProductExample.Criteria criteria = example.createCriteria();
        criteria.andProductStatusEqualTo(1);
        criteria.andBigIdEqualTo(bigId);
        return productMapper.selectByExample(example);
    }*/

//    /*根据商品id查询*/
//    @Override
//    public List<Product> getByProId(int proId) {
//        Product product = null;
//        ProductExample productExample = new ProductExample();
//        ProductExample.Criteria criteria = productExample.createCriteria();
//        criteria.andProductIdEqualTo(proId);
//        criteria.andProductStatusEqualTo(1);
//        List<Product> productList = productMapper.selectByExample(productExample);
//        for (Product p:productList){
//            proId = p.getProductId();
//            product = productMapper.selectByPrimaryKey(proId);
//            System.out.println(proId);
//        }
//        return productList;
//    }

    /*根据商品id查询*/
    @Override
    public Product getByProId(int proId){
        return productMapper.selectByPrimaryKey(proId);
    }

    @Override
    public ServerResponse getByName(String proName) {
        ProductExample productExample = new ProductExample();
        productExample.createCriteria().andProductNameEqualTo(proName).andProductStatusEqualTo(1);
        List<Product> productList = productMapper.selectByExample(productExample);
        if (productList != null && productList.size()>0)
            return ServerResponse.getDataSuccess(productList.get(0));
        return ServerResponse.getDataFailed("暂无数据");
    }


}
